package com.derbysoft.dswitch.adapter.ihg.common.repository.impl;

import com.derbysoft.dswitch.adapter.ihg.common.domain.Reservation;
import com.derbysoft.dswitch.adapter.ihg.common.domain.ReservationItem;
import com.derbysoft.dswitch.adapter.ihg.common.repository.ReservationItemRepository;
import com.derbysoft.dswitch.adapter.ihg.web.action.admin.reservation.ReservationInfo;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository("reservationItemRepository")
public class ReservationItemRepositoryImpl extends CommonService<ReservationItem> implements ReservationItemRepository {

    private static final String ERSP = "ersp";

    @Override
    public List<ReservationInfo> loadAll(List<Reservation> reservations) {
        List<ReservationInfo> reservationItems = new ArrayList<ReservationInfo>();
        for (Reservation reservation : reservations) {
            ReservationItem reservationItem = loadByErsp(reservation.getErsp());
            reservationItems.add(ReservationInfo.of(reservation, reservationItem));
        }
        return reservationItems;
    }

    @Override
    public ReservationItem loadByConfirm(String confirmNumber) {
        return load("confirmNumber", confirmNumber);
    }

    @Override
    public ReservationItem loadByErsp(String ersp) {
        return load(ERSP, ersp);
    }
}